# encoding=utf-8
# author:梁子龙
from celery import shared_task
from buleking.celery import app

from user.models import UserModel

"""
[tasks]
  . celeryapp.tasks.add
  . celeryapp.tasks.arrange_task
  . proj.celery_task.send
  . user.tasks.add
  . user.tasks.arrange_task

"""
#from django_celery_results.models import TaskResult, GroupResult


# celery -A buleking  worker -l info -P eventlet
@app.task
def add():
    x, y = 1, 2
    print("这是打印的")
    return x + y


# @shared_task
# def add(x, y):
#     print("这是打印的")
#     return x + y

@shared_task
def arrange_task():
    user = UserModel.objects.filter(username="django").first()
    staff = user.is_staff
    if staff == True:
        user.is_staff = False
        user.save()
    else:
        user.is_staff = True
        user.save()
    print(staff, "flag", "这是打印的")
    return 0
# celery -A buleking  worker -l info -P eventlet
# celery -A buleking  worker -l info -P eventlet -Q metric
# 启动 Celery worker
# celery -A myproject worker -l info

# 启动 Celery Beat
# celery -A myproject beat -l info --scheduler django_celery_beat.schedulers:DatabaseScheduler
